import re

from prefect import task
import pandas as pd
from prefect import get_run_logger

from prefect import Task, Flow

from application.tasks.base_task import BaseTask


class TranslateTimeTask(BaseTask):
    def run(self, df: pd.DataFrame):
        df['info_date'] = df['info_date'].apply(self.cleaning_date)  # 时间字段清洗
        return df

    @staticmethod
    def cleaning_date(date):
        if not date:
            return date
        match = re.search(r'\d{4}-\d{1,2}-\d{1,2}', date)
        if match:
            # print(match.group())
            date = match.group()
        return date
